<template>
  <div class="user-management-container">
    <vab-query-form>
      <el-form inline :model="queryForm" @submit.prevent>
        <el-form-item>
          <el-input
            v-model.trim="queryForm.title"
            clearable
            placeholder="请输入选题名称"
          />
        </el-form-item>
        <el-form-item>
          <el-button :icon="Search" type="primary" @click="queryData">
            查询
          </el-button>
        </el-form-item>
      </el-form>
    </vab-query-form>

    <el-table
      v-loading="listLoading"
      border
      :data="list"
      @selection-change="setSelectRows"
    >
      <!--      <el-table-column align="center" show-overflow-tooltip type="selection" />-->
      <el-table-column align="center" label="序号" width="55">
        <template #default="{ $index }">
          {{ $index + 1 }}
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="平台账号"
        prop="platformAccount"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="选题名称"
        prop="title"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="预计完成时间"
        prop="projectTime"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="选题内容"
        prop="details"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="图片"
        prop="pic"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="成本费用"
        prop="fee"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="实际发布时间"
        prop="reportTime"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="汇报状态"
        prop="status"
        show-overflow-tooltip
      >
        <template #default="{ row }">
          <span>
            {{
              row.status === 1
                ? '选题已完成'
                : row.status === 2
                ? '任务已完成'
                : row.status === 3
                ? '成果已汇报'
                : ''
            }}
          </span>
        </template>
      </el-table-column>
      <el-table-column
        align="center"
        label="创建时间"
        prop="createTime"
        show-overflow-tooltip
      />
      <el-table-column
        align="center"
        label="操作"
        show-overflow-tooltip
        width="150"
        fixed="right"
      >
        <template #default="{ row }">
          <!--          <el-button-->
          <!--            v-permissions="{ role: ['ROOT'], permission: ['sys:user:edit'] }"-->
          <!--            text-->
          <!--            type="primary"-->
          <!--            @click="handleDetail(row)"-->
          <!--          >-->
          <!--            详情-->
          <!--          </el-button>-->
          <el-tooltip
            class="box-item"
            effect="dark"
            content="详情"
            placement="top"
          >
            <el-button
              :icon="InfoFilled"
              type="warning"
              @click="handleDetail(row)"
            />
          </el-tooltip>
        </template>
      </el-table-column>
      <template #empty>
        <el-empty class="vab-data-empty" description="暂无数据" />
      </template>
    </el-table>
    <el-pagination
      background
      :current-page="queryForm.pageNum"
      :layout="layout"
      :page-size="queryForm.pageSize"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />
    <edit ref="editRef" @fetch-data="fetchData" />
  </div>
</template>

<script>
  // import { details, doDelete, getList } from '@/api/userManagement'
  import {
    // deleteSelectTopic,
    fetchSelectTopicList,
    // fetchSelectTopicDetail,
  } from '@/api/topics'
  // import {
  //   fetchAccountList,
  // } from '@/api/accountManagement'
  // import { getList as fetchRoleList } from '@/api/roleManagement'
  import {
    Delete,
    Plus,
    Search,
    Edit,
    InfoFilled,
  } from '@element-plus/icons-vue'
  import { useAclStore } from '@/store/modules/acl'
  export default defineComponent({
    name: 'UserManagement',
    components: {
      Edit: defineAsyncComponent(() => import('./components/Edit')),
    },
    setup() {
      // const $baseConfirm = inject('$baseConfirm')
      // const $baseMessage = inject('$baseMessage')
      const router = useRouter()
      const aclStore = useAclStore()
      const { role, permission } = storeToRefs(aclStore)
      const state = reactive({
        editRef: null,
        roleList: [],
        list: [],
        listLoading: true,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        selectRows: '',
        queryForm: {
          pageNum: 1,
          pageSize: 10,
          username: '',
        },
      })

      const setSelectRows = (val) => {
        state.selectRows = val
      }
      const handleDetail = (row) => {
        console.log(row, '111')
        router.push(
          `/operaction/strategicReportDetails?id=${row.id}&platformId=${row.platformId}`
        )
      }
      const handleSizeChange = (val) => {
        state.queryForm.pageSize = val
        fetchData()
      }
      const handleCurrentChange = (val) => {
        state.queryForm.pageNum = val
        fetchData()
      }
      const queryData = () => {
        state.queryForm.pageNum = 1
        fetchData()
      }
      const fetchData = async () => {
        try {
          state.listLoading = true
          const {
            data: { list, total },
          } = await fetchSelectTopicList(state.queryForm)
          state.list = list
          state.total = total
          state.listLoading = false
        } catch (e) {
          console.log(e)
        }
      }
      onMounted(() => {
        fetchData()
        // fetchAccount()
      })

      return {
        ...toRefs(state),
        setSelectRows,
        handleSizeChange,
        handleCurrentChange,
        queryData,
        fetchData,
        handleDetail,
        Delete,
        Plus,
        Search,
        role,
        permission,
        Edit,
        InfoFilled,
      }
    },
  })
</script>
<style scoped>
  .toolbar {
    margin-bottom: 4px;
  }

  :deep() {
    .cell .el-button {
      width: 32px;
    }
  }
</style>
